
package c;

import javax.swing.table.DefaultTableModel;
import org.jdesktop.swingx.JXTable;

/**
 *
 * @author Sebas
 */
public class JXtableController extends Controller {

    DefaultTableModel model = null;
    Object[][] datos = null;
    int totalAntes = 0;

    public JXtableController(JXTable tabla, Object[][] datos) {
        this.model = (DefaultTableModel) tabla.getModel();
        this.totalAntes = this.model.getRowCount();
        this.datos = datos;
        this.borrarElementosDiferentesALaBusqueda();
        this.addElementosEncontrados();
        

    }

    private void addElementosEncontrados() {
        for (int n = 0; n < this.datos.length; n++) {
            this.model.addRow(datos[ n]);
        }
    }

    private void borrarElementosDiferentesALaBusqueda() {
        try {
            for (int n = (this.totalAntes - 1); n >= 0; n--) {
                this.model.removeRow(n);

            }
        } catch (ArrayIndexOutOfBoundsException e) {
            System.out.println("Error : " + e.getMessage());
        }
    }
}
